import React, {Component} from 'react'
import {render} from 'react-dom'
    // const { Map, Marker } = window.ReactBMap;
import {Map, Marker, NavigationControl, InfoWindow,ScaleControl,
  OverviewMapControl,MapTypeControl,
  Polyline,Circle,Polygon,
MarkerList,
Boundary,
Road,
MapvLayer,
TrafficLayer} from 'react-bmap';

const map ={};
export default class bdMapSz extends Component {
  constructor(props) {
    super(props);
    this.state = {
        boundarydata:[
                {
                    name:"宝安区",
                                count: 20

                }, {
                    name:"盐田区",
                                count: 20

                }
            ]
    };
  }

  componentDidMount =()=> {
         this.map = this.refs.map.map;
      
    // this.init()
  }

  search =() =>{
  }

searchFn = () =>{
    
      let local = new BMap.LocalSearch(map, {
		renderOptions:{map: map,panel: "r-result"}
	});
	local.search( this.refs.searchWord.value)
}
  init =() => {
      //
		let bdary = new BMap.Boundary();
        let map = this.refs.map.map;
		bdary.get("广东省深圳市", (rs) =>{       //获取行政区域
			map.clearOverlays();        //清除地图覆盖物       
			let count = rs.boundaries.length; //行政区域的点有多少个
			if (count === 0) {
				alert('未能获取当前输入行政区域');
				return ;
			}
          	let pointArray = [];
			for (let i = 0; i < count; i++) {
				let ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //
                
				map.addOverlay(ply);  //添加覆盖物
				pointArray = pointArray.concat(ply.getPath());
			}    
			map.setViewport(pointArray);    //调整视野  
			//addlabel();               
		});   
        

  }

  render() {
    let mapConfig = {
      boxW: '500px',
      boxH: '300px',
    }
    return (
      <div className='bdMapSz'>
                <input type="" name=""  ref='searchWord' />
                 <button type="" onClick = {this.searchFn}>搜索</button>
                 <div id="r-result">
                     
                 </div>
                <Map ref='map'
                center= '深圳市'
                zoom="8" 
                >
                </Map>
      </div>
    )
  }
}
 